<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" name="lian_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var param_enginid = getQueryVariable('enginid') || 0;

    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('应扣费用表');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_engin_kou_list),where: {enginid:param_enginid}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })


                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type:'numbers',title:'序号',totalRowText: '合计',rowspan:2}
                ,{field: 'name', title: '项目名称',rowspan:2}
                ,{field: 'chanid_name', title: '项目所属单位',rowspan:2}
                ,{field: 'lian_unit', title: '委托方',rowspan:2}
                ,{field: 'gonghuifee', title: '其中工程回款金额(元)',rowspan:2,totalRow: true,align:'right',event: 'income_engin_gong',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.gonghuifee)+'</span>';
                    }}
                ,{field: 'lei_piaokai', title: '累计开票金额(元)',rowspan:2,totalRow: true,align:'right',event: 'piao_kai',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.lei_piaokai)+'</span>';
                    }}
                ,{field: '', title: '管理费(元)',colspan:4,align:'center'}
                ,{field: '', title: '成本票差额费(元)',colspan:4,align:'center'}
                ,{field: '', title: '税费(元)',colspan:3,align:'center'}
                ,{field: '', title: '税费利息(元)',colspan:3,align:'center'}
                ,{field: 'ying_all', title: '应扣合计(元)',align:'right',rowspan:2,totalRow: true,templet: function(d){return parseFormatNum(d.ying_all);}}
                ,{field: 'yi_all', title: '已扣合计(元)',align:'right',rowspan:2,totalRow: true,templet: function(d){return parseFormatNum(d.yi_all);}}
                ,{field: 'dai_all', title: '待扣合计(元)',align:'right',rowspan:2,totalRow: true,templet: function(d){return parseFormatNum(d.dai_all);}}
            ],
            [
                {field: 'guanrate', title: '比例(%)'}
                ,{field: 'guanying', title: '应扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.guanying);}}
                ,{field: 'guanyi', title: '已扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.guanyi);}}
                ,{field: 'guandai', title: '待扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.guandai);}}


                ,{field: 'charate', title: '比例(%)'}
                ,{field: 'chaying', title: '应扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.chaying);}}
                ,{field: 'chayi', title: '已扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.chayi);}}
                ,{field: 'chadai', title: '待扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.chadai);}}

                ,{field: 'shuiying', title: '应扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.shuiying);}}
                ,{field: 'shuiyi', title: '已扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.shuiyi);}}
                ,{field: 'shuidai', title: '待扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.shuidai);}}

                ,{field: 'lixiying', title: '应扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.lixiying);}}
                ,{field: 'lixiyi', title: '已扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.lixiyi);}}
                ,{field: 'lixidai', title: '待扣(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.lixidai);}}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'piao_kai'){
                openNavPage('开票信息','piao_kai/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'income_engin_gong'){
                openNavPage('项目工程回款信息','income_engin/index.php?enginid='+data.id+'&status=1&gongkuan=1');
            }
        });

        listTableSearch(form, table);
    });



    function auth_but_func_she(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        if(checkStatus.length != 1){
            facade.error(buttitle + "：请选择单条数据");return false;
        }
        openPageEdit('../engin/she.php?close=1&id='+checkStatus[0].id);
    }

</script>
</body>
</html>
